#pragma once

#include <QWidget>
#include <QVBoxLayout>
#include <QPushButton>
#include <QPropertyAnimation>

class DockTab;

/**
 * TabDrawer - 抽屉式标签页容器
 * 可展开/折叠的侧边栏标签页容器
 */
class TabDrawer : public QWidget {
    Q_OBJECT
    Q_PROPERTY(int contentHeight READ contentHeight WRITE setContentHeight)
    
public:
    explicit TabDrawer(const QString& title, QWidget* parent = nullptr);
    explicit TabDrawer(DockTab* tab, QWidget* parent = nullptr);
    ~TabDrawer();
    
    // === 基础属性 ===
    QString title() const { return m_title; }
    void setTitle(const QString& title);
    
    QIcon icon() const { return m_icon; }
    void setIcon(const QIcon& icon);
    
    // === 内容管理 ===
    QWidget* content() const { return m_content; }
    void setContent(QWidget* content);
    
    DockTab* associatedTab() const { return m_associatedTab; }
    void setAssociatedTab(DockTab* tab);
    
    // === 展开/折叠 ===
    bool isExpanded() const { return m_isExpanded; }
    void setExpanded(bool expanded, bool animated = true);
    void toggle() { setExpanded(!m_isExpanded); }
    
    // === 动画属性 ===
    int contentHeight() const;
    void setContentHeight(int height);

signals:
    void toggled(bool expanded);
    void titleClicked();
    void contentChanged(QWidget* content);

protected:
    void paintEvent(QPaintEvent* event) override;
    QSize sizeHint() const override;
    QSize minimumSizeHint() const override;

private slots:
    void onTitleButtonClicked();
    void onAnimationFinished();

private:
    void setupDrawer();
    void updateTitleButton();
    void startAnimation(int fromHeight, int toHeight);

private:
    QString m_title;
    QIcon m_icon;
    QWidget* m_content;
    DockTab* m_associatedTab;
    
    // UI组件
    QVBoxLayout* m_mainLayout;
    QPushButton* m_titleButton;
    QWidget* m_contentWidget;
    QVBoxLayout* m_contentLayout;
    
    // 状态
    bool m_isExpanded;
    int m_expandedHeight;
    
    // 动画
    QPropertyAnimation* m_animation;
    
    static const int TITLE_HEIGHT = 30;
    static const int DEFAULT_CONTENT_HEIGHT = 200;
};

